package SteamEngineFX;

//import java.awt.Image;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import SteamEngineFX.Layouts.ApplicationPane;
import SteamEngineFX.data.SteamEngineConnection;
import SteamEngineFX.util.DialogFX;
import javafx.scene.image.Image;
import org.joda.time.LocalDate;
/**
 *
 * @author jbendixsen
 */
public class SteamEngineFX extends Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Application.launch(args);
    }
    
    private static final Image Locomotive32 = new Image(SteamEngineFX.class.getResourceAsStream("/steamenginefx/resources/Locomotive32.png"));
    
    private ApplicationPane root = null;
    
    private Scene scene = null;
    private DialogFX dialog = null;
    
    //private SEProperties props = null;
    
    private SteamEngineConnection conn = null;
    
    
    @Override
    public void start(Stage primaryStage) {
        
        primaryStage.setTitle("Reservations");
        
        primaryStage.getIcons().add(Locomotive32);
        
        dialog = new DialogFX();
            //props = new SEProperties();
        //props.listProperties();
        
        try{
            conn = new SteamEngineConnection(AppConst.UNIT_NAME);
        }catch(RuntimeException ex){
            dialog.Show(DialogFX.DialogType.ERROR, "Cannot connect to database");
            return;
//            throw ex;
        }
        //dialog.Show(DialogFX.DialogType.ERROR, "Connected to the database");
        
        
        root = new ApplicationPane(this, primaryStage, conn);
        
        scene = new Scene(root, 800, 600);
        scene.getStylesheets().addAll(AppConst.defaultStyleSheet, AppConst.calendarStyleSheet);
        
        primaryStage.setScene(scene);

        //On startup default to todays's date
        root.initSelectedDate(new LocalDate());
        
        root.setStatus("Ready");
        
        primaryStage.show();
        
    }
    
}
